home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Gfx / Edit / TSMorph / src / loadilbm.c < prev    next >
C/C++ Source or Header  |  1994-10-30  |  5KB  |  214 lines

  1. /* loadilbm.c - C. Scheppner CBM
  2.  *
  3.  * High-level ILBM load routines
  4.  *
  5.  * 37.9  04/92 - use vp->ColorMap.Count instead of MAXAMCOLORREG
  6.  */
  7. // Minor edits for error handling MJP
  8.  
  9. #define INTUI_V36_NAMES_ONLY
  10.  
  11. #include "iffp/ilbm.h"
  12. #include "iffp/ilbmapp.h"
  13.  
  14. extern struct Library *GfxBase;
  15.  
  16. /* loadbrush
  17.  *
  18.  * Passed an initialized ILBMInfo with a not-in-use ParseInfo.iff
  19.  *   IFFHandle and desired propchks, collectchks, and stopchks, and filename,
  20.  *   will load an ILBM as a brush, setting up ilbm->Bmhd, ilbm->camg,
  21.  *   ilbm->brbitmap, ilbm->colortable, and ilbm->ncolors
  22.  *
  23.  *   Note that ncolors may be more colors than you can LoadRGB4.
  24.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  25.  *   you change the colors yourself using 1.3/2.0 functions.
  26.  *
  27.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  28.  */
  29.  
  30. LONG loadbrush(struct ILBMInfo *ilbm, UBYTE *filename)
  31. {
  32. LONG error = 0L;
  33.  
  34.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  35.  
  36.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  37.     {
  38.     error = parseifile((struct ParseInfo *)ilbm,
  39.                 ID_FORM, ID_ILBM,
  40.                 ilbm->ParseInfo.propchks,
  41.                 ilbm->ParseInfo.collectchks,
  42.                 ilbm->ParseInfo.stopchks);
  43.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  44.         {
  45.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  46.         {
  47.             if(error = createbrush(ilbm))   deletebrush(ilbm);
  48.         }
  49.         else
  50.         {
  51.         message(SI(MSG_IFFP_NOILBM),NULL,6);        // MJP 6 = IFFILBM
  52.         error = NOFILE;
  53.         }
  54.         }
  55.     if(error)    closeifile((struct ParseInfo *)ilbm);
  56.     }
  57.     return(error);
  58. }
  59.  
  60.  
  61. /* unloadbrush
  62.  *
  63.  * frees and close everything alloc'd/opened by loadbrush
  64.  */
  65. void unloadbrush(struct ILBMInfo *ilbm)
  66. {
  67.     deletebrush(ilbm);
  68.     closeifile((struct ParseInfo *)ilbm);
  69. }
  70.  
  71.  
  72. /* queryilbm
  73.  *
  74.  * Passed an initilized ILBMInfo with a not-in-use IFFHandle,
  75.  *   and a filename,
  76.  *   will open an ILBM, fill in ilbm->camg and ilbm->bmhd,
  77.  *   and close the ILBM.
  78.  *
  79.  * This allows you to determine if the ILBM is a size and
  80.  *   type you want to deal with.
  81.  *
  82.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  83.  */
  84.  
  85. /* query just wants these chunks */
  86. LONG queryprops[] = { ID_ILBM, ID_BMHD,
  87. //              ID_ILBM, ID_CAMG,
  88.                       TAG_DONE };
  89.  
  90. /* scan can stop when a CMAP or BODY is reached */
  91. LONG querystops[] = { ID_ILBM, ID_CMAP,
  92.               ID_ILBM, ID_BODY,
  93.               TAG_DONE };
  94.  
  95. LONG queryilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  96. {
  97. LONG error = 0L;
  98. BitMapHeader *bmhd;
  99.  
  100.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  101.  
  102.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  103.     {
  104.     D(bug("queryilbm: openifile successful\n"));
  105.  
  106.     error = parseifile((struct ParseInfo *)ilbm,
  107.             ID_FORM, ID_ILBM,
  108.             queryprops, NULL, querystops);
  109.  
  110.     D(bug("queryilbm: after parseifile, error = %ld\n",error));
  111.  
  112.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  113.         {
  114.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  115.         {
  116.         if(bmhd = (BitMapHeader*)
  117.             findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD))
  118.             {
  119.             *(&ilbm->Bmhd) = *bmhd;
  120. //            ilbm->camg = getcamg(ilbm);    MJP
  121.             }
  122.         else error = NOFILE;
  123.         }
  124.         else
  125.         {
  126. //        message(SI(MSG_IFFP_NOILBM),NULL,6);        // MJP
  127.         error = NOFILE;
  128.         }
  129.         }
  130.     closeifile(ilbm);
  131.     }
  132.     return(error);
  133. }
  134.  
  135. /* loadilbm
  136.  *
  137.  * Passed a not-in-use IFFHandle, an initialized ILBMInfo, and filename,
  138.  *   will load an ILBM into your already opened ilbm->scr, setting up
  139.  *   ilbm->Bmhd, ilbm->camg, ilbm->colortable, and ilbm->ncolors
  140.  *   and loading the colors into the screen's viewport
  141.  *
  142.  *   Note that ncolors may be more colors than you can LoadRGB4.
  143.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  144.  *   you change the colors yourself using 1.3/2.0 functions.
  145.  *
  146.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  147.  *
  148.  * NOTE - loadilbm() keeps the IFFHandle open so you can copy
  149.  *   or examine other chunks.  You must call closeifile(iff,ilbm)
  150.  *   to close the file and deallocate the parsed context
  151.  *
  152.  */
  153. /*    MJP
  154. LONG loadilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  155. {
  156. LONG error = 0L;
  157.  
  158.  
  159.     D(bug("loadilbm:\n"));
  160.  
  161.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  162.     if(!ilbm->scr)        return(CLIENT_ERROR);
  163.  
  164.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  165.     {
  166.     D(bug("loadilbm: openifile successful\n"));
  167.  
  168.     error = parseifile((struct ParseInfo *)ilbm,
  169.             ID_FORM, ID_ILBM,
  170.             ilbm->ParseInfo.propchks,
  171.             ilbm->ParseInfo.collectchks,
  172.             ilbm->ParseInfo.stopchks);
  173.  
  174.     D(bug("loadilbm: after parseifile, error = %ld\n",error));
  175.  
  176.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  177.         {
  178.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  179.         {
  180.             error = loadbody(ilbm->ParseInfo.iff,
  181.                     &ilbm->scr->BitMap, &ilbm->Bmhd);
  182.  
  183.         D(bug("loadilbm: after loadbody, error = %ld\n",error));
  184.  
  185.         if(!error)
  186.             {
  187.             if(!(getcolors(ilbm)))
  188.                 LoadRGB4(&ilbm->scr->ViewPort,ilbm->colortable,
  189.             MIN(ilbm->ncolors,ilbm->scr->ViewPort.ColorMap->Count));
  190.             } 
  191.         }
  192.         else
  193.         {
  194.         message(SI(MSG_IFFP_NOILBM),NULL,6);        // MJP
  195.         error = NOFILE;
  196.         }
  197.         }
  198.     if(error)    closeifile((struct ParseInfo *)ilbm);
  199.     }
  200.     return(error);
  201. }
  202. */
  203.  
  204. /* unloadilbm
  205.  *
  206.  * frees and closes everything allocated by loadilbm
  207.  */
  208. /* MJP
  209. void unloadilbm(struct ILBMInfo *ilbm)
  210. {
  211.     closeifile((struct ParseInfo *)ilbm);
  212.     freecolors(ilbm);
  213. }
  214. */